package com.cncbox.service.impl;

import org.springframework.beans.factory.annotation.Autowired;

import com.cncbox.common.Utils;
import com.cncbox.dao.UserDao;
import com.cncbox.entity.NoteResult;
import com.cncbox.entity.User;
import com.cncbox.service.UserManagerService;

/**
 * @author Develop_Peng
 * @version V1.0
 * @Title: UserManagerServiceImpl.java
 * @Package com.cncbox.service.impl
 * @Description: 用户Service实现类(类描述)
 * @date 2016年3月28日 上午11:21:08
 */
public class UserManagerServiceImpl implements UserManagerService {

    @Autowired
    private UserDao userDao;

    // 校验用户登陆
    public NoteResult checkUserNamePassword(User user) throws Exception {

        NoteResult result = new NoteResult();

        // 进行密码加密处理
        user.setPassword(Utils.setEncryption(user.getPassword()));
        Integer selectResult = userDao.checkUserNameAndPassword(user);
        if (selectResult != null || 0 < selectResult) {
            result.setStatus(1);
            result.setMsg("LOGIN_SUCCESS");
            result.setData(selectResult);
            return result;
        } else {
            result.setStatus(0);
            result.setMsg("LOGIN_ERROR");
            return result;
        }
    }

    //修改用户密码
    public NoteResult updateUserPassword(String password) throws Exception {
        NoteResult result = new NoteResult();

        Boolean userPassword = userDao.updateUserPassword(Utils.setEncryption(password));
        if (userPassword) {
            result.setStatus(1);
            result.setMsg("UPDATE_SUCCESS");
        } else {
            result.setStatus(0);
            result.setMsg("UPDATE_ERROR");
        }
        return result;
    }
}
